package BiShi.jingdong;


        import java.util.Arrays;
        import java.util.Comparator;
        import java.util.HashMap;
        import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int[] arr = new int[n];
            int res = 0;
            res = helper(arr, 1, 0);

            System.out.println(res);
        }
    }

    private static int helper(int[] arr, int i1, int i) {
        if(i1==arr.length-1) return i;
        int a1 = helper(arr, arr[i1]-1, i);
        int a2 = helper(arr, arr[i1]+1, i);
        return Math.min(a1,a2);
    }
}


